package com.ev.asl.service.impl;

import com.ev.asl.constant.AslConstant;
import com.ev.asl.dao.AssemblyInstructionDao;
import com.ev.asl.domain.AssemblyInstructionDO;
import com.ev.asl.service.AssemblyInstructionService;
import com.ev.framework.utils.DateUtils;
import com.ev.mes.service.ProductionFeedingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 姚家乐
 * @since 2021/6/22 9:14
 */
@Service
public class AssemblyInstructionServiceImpl implements AssemblyInstructionService {

    @Autowired
    private AssemblyInstructionDao   dao;

    @Autowired
    private ProductionFeedingService productionFeedingService;

    @Override
    public int save(AssemblyInstructionDO entity) {
        entity.setDelFlag(AslConstant.NO);
        entity.setHaveFirstCheck(AslConstant.NO);
        entity.setStatus(AslConstant.AssemblyInstruction.PLAN.getType());
        return dao.save(entity);
    }

    @Override
    public AssemblyInstructionDO get(Long id) {
        return dao.get(id);
    }

    @Override
    public Map<String, Object> getDetailInfo(Long id) {
        Map<String, Object> result = dao.getDetailInfo(id);
        result.put("indicateDate", DateUtils.format((Date) result.get("indicateDate")));
        result.put("startDate", DateUtils.format((Date) result.get("startDate"),DateUtils.DATE_TIME_PATTERN));
        result.put("endDate", DateUtils.format((Date) result.get("endDate"),DateUtils.DATE_TIME_PATTERN));
        Long planId = Long.valueOf(String.valueOf(result.get("productionPlanId")));
        List<Map<String, Object>> feedingMateriel = productionFeedingService
            .aslGetFeedingByPlanId(planId);
        result.put("feedingMateriel", feedingMateriel);
        return result;
    }

    @Override
    public Map<String, Object> getDetail(Long id) {
        Map<String, Object> result = dao.getDetail(id);
        return result;
    }

    @Override
    public int update(AssemblyInstructionDO entity) {
        return dao.update(entity);
    }

    @Override
    public int batchUpdate(List<AssemblyInstructionDO> entitys) {
        return dao.batchUpdate(entitys);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return dao.batchRemove(ids);
    }

    @Override
    public int remove(Long id) {
        return dao.remove(id);
    }

    @Override
    public List<AssemblyInstructionDO> list(Map<String, Object> param) {
        return dao.list(param);
    }

    @Override
    public int countForMap(Map<String, Object> params) {
        return dao.countForMap(params);
    }

    @Override
    public List<Map<String, Object>> listForMap(Map<String, Object> param) {
        return dao.listForMap(param);
    }

    @Override
    public List<Long> getPlanIds() {
        return dao.getPlanIds();
    }
}
